<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
// import resize from './mixins/resize'

export default {
  // mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart"
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "300px"
    }
  },
  computed: {
    linetwo() {
      //dissatisfy基本满意 normal不满意数量  satisfaction满意数量
      return this.$store.state.hcem.TwoData.submissionAmountList
    },
    XData() {
      const arr = []
      if (this.linetwo.length > 0) {
        this.linetwo.map(v => {
          arr.push(v.day)
        })
      } else {
        arr.push(0)
      }
      return arr
    },
    YData() {
      const arr = []
      if (this.linetwo.length > 0) {
        this.linetwo.map(v => {
          arr.push(v.count)
        })
      } else {
        arr.push(0)
      }
      return arr
    }
  },
  watch: {
    linetwo() {
      this.options()
    }
  },
  data() {
    return {
      chart: null
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      this.options()
    },
    options() {
      this.chart.setOption({
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985"
            }
          }
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: this.XData
        },
        yAxis: {
          //min:1,
          type: "value"
        },
        series: [
          {
            data: this.YData,
            type: "line",
            areaStyle: {}
          }
        ]
      });
    }
  }
};
</script>
